#!/bin/sh

[ -d /root/TED/daily_archives ] || mkdir -p /root/TED/daily_archives
cd /root/TED/daily_archives

DATENOW=`date +%Y%m%d`
mkdir $DATENOW
cd $DATENOW

DATEFNOW=`date +%D`

LOCALHOST="OpenWrt"

rrdtool graph '1.86400.png' '-a' PNG '-s' 'NOW-86400' '-w' 400 '-t' $LOCALHOST': KiloWatt Hours used ' '-v' 'kilowatt hours' 'DEF:1kwhrtdysum_avg=/tmp/'$LOCALHOST'/ted/kwhrtdysum.rrd:value:AVERAGE' 'CDEF:1kwhrtdysum_nnl=1kwhrtdysum_avg,UN,0,1kwhrtdysum_avg,IF' 'CDEF:1kwhrtdysum_stk=1kwhrtdysum_nnl' 'LINE1:1kwhrtdysum_stk#0000ff:kwhrtdysum__value' 'GPRINT:1kwhrtdysum_avg:AVERAGE:	Avg\: %6.1lf' 'GPRINT:1kwhrtdysum_avg:LAST:	Last\: %6.1lf\l'
rrdtool graph '2.86400.png' '-a' PNG '-s' 'NOW-86400' '-w' 400 '-t' $LOCALHOST': KiloWatt usage for '$DATEFNOW '-v' kilowatts 'DEF:1kwnowdsp_avg=/tmp/'$LOCALHOST'/ted/kwnowdsp.rrd:value:AVERAGE' 'CDEF:1kwnowdsp_nnl=1kwnowdsp_avg,UN,0,1kwnowdsp_avg,IF' 'CDEF:1kwnowdsp_stk=1kwnowdsp_nnl' 'LINE1:1kwnowdsp_stk#0000ff:kwnowdsp__value' 'GPRINT:1kwnowdsp_avg:AVERAGE:	Avg\: %6.1lf' 'GPRINT:1kwnowdsp_avg:LAST:	Last\: %6.1lf\l'

cp /tmp/$LOCALHOST/ted/kwhrtdysum.rrd .
cp /tmp/$LOCALHOST/ted/kwnowdsp.rrd .

chmod 444 *

